@extends('admin.main')
@section('head')
    <style>
        .buyer {
            color: #555;
            position: relative;
            display: block;
        }

        .buyer-info {
            display: none;
            width: 450px
        }

        .buyer:hover .buyer-info {
            *width: 250px /*IE7*/;
            display: block;
            position: absolute;
            z-index: 8;
            top: -40px;
            left: 40px;
            border: solid 1px #FEC500;
            background-color: #FFF9D4;
            padding: 4px;
            border-radius: 5px;
        }

        .buyer-info em {
            width: 8px;
            height: 14px;
            position: absolute;
            z-index: 9;
            top: 37px;
            left: -8px;
        }

        .buyer-info .con {
            display: block;
            overflow: hidden;
            background: #FFF;
            padding: 5px;
        }

        .buyer-info h3 {
            font-size: 1em;
            font-weight: 700;
            color: #C33700;
            padding: 5px 0;
            overflow: hidden;
        }

        .buyer-info h3 i {
            width: 17px;
            height: 11px;
            float: left;
            margin: 5px 5px 4px 12px;
        }

        .buyer-info h3 span {
            float: left;
        }

        .buyer-info dl {
            color: #777;
            padding: 2px 0;
            width: 420px;
            overflow: hidden;
            clear: both;
        }

        .buyer-info dt {
            float: left;
            width: 100px;
            text-align: right;
        }

        .buyer-info dd {
            float: left;
            width: 320px;
            text-align: left;
        }

        .select_box {
            position: relative;
            padding: 0;
            display: inline-block;
            zoom: 1;
            *zoom: 1;
            *display: inline;
        }

        .select_box input:hover {
        }

        .select_box ul {
            width: 150px;
            position: absolute;
            left: 0;
            top: 28px;
            border: 1px solid #85BEE5;
            overflow: hidden;
            display: none;
            background: white;
            z-index: 9999;
        }

        .select_box ul li {
            display: block;
            height: 25px;
            overflow: hidden;
            line-height: 25px;
            padding-left: 5px;
            width: 100%;
            cursor: pointer;
        }

        .select_box ul li:hover {
            background: #d2eaff;
        }
    </style>
@endsection
@section('body')
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>用户列表</h2>
    </div>
    <div class="cf">
        @if(plat_identify() == 'account')
            <div class="fl">
                <a class="btn" href="{{urlPlat('single','getMemberAdd',['shop_id'=>request('shop_id')])}}">新 增</a>
            </div>
        @endif
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div style="float: left;margin-right: 10px;line-height: 26px;">
                <select name="type" id="type" style="height: 30px;">
                    <option value="0" @if($type == 0) selected @endif>请选择搜索类型</option>
                    <option value="1" @if($type == 1) selected @endif>ID</option>
                    <option value="2" @if($type == 2) selected @endif>姓名</option>
                    <option value="3" @if($type == 3) selected @endif>手机号</option>
                    <option value="4" @if($type == 4) selected @endif>公司名称</option>
                    <option value="5" @if($type == 5) selected @endif>地址</option>
                </select>
            </div>
            <div class="sleft">
                <input type="text" name="keyword" class="search-input" value="{{$keyword}}"
                       placeholder="请输入对应的搜索内容">
                <a class="sch-btn" href="javascript:;" id="search" url="{{urlPlat('single','getMember')}}"><i
                            class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="">
            <thead>
            <tr>
                @if(plat_identify() == 'account')<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>@endif
                <th class="">ID</th>
                <th class="">类型</th>
                <th class="">头像</th>
                <th class="">昵称</th>
                <th class="">姓名</th>
                <th class="">手机号</th>
                <th class="">单位名称</th>
                <th class="">地址</th>
                <th class="">水票余额</th>
                <th class="">欠桶数量</th>
                <th class="">押金</th>
                <th class="">状态</th>
                    <th class="">查看明细</th>
                @if(isset($shopInfo['send_mode']) && $shopInfo['send_mode'] == 2)
                    <th class="">绑定送水工</th>
                @endif
                <th class="">创建时间</th>
                @if(plat_identify() == 'account')<th class="">操作</th>@endif
            </tr>
            </thead>
            <tbody>
            @if(count($rows['data']))
                @foreach($rows['data'] as $v)
                    <tr>
                        @if(plat_identify() == 'account')<td><input class="ids" type="checkbox" name="ids[]" value="{{$v['id']}}"/></td>@endif
                        <td>{{$v['id']}}</td>
                            <td>{{$v['address'] ? $v['address']['type'] == 1 ? '单位': ($v['address']['type'] == 2 ? '家庭' : '') : ''}}</td>
                            <td><img src="{{$v['avatarurl']}}" width="20px"/></td>
                            <td>{{$v['nickname']}}</td>
                            <td>{{$v['address'] ? $v['address']['name'] : ''}}</td>
                            <td>{{$v['address'] ? $v['address']['mobile'] : ''}}</td>
                            <td>{{$v['address'] ? $v['address']['company_name'] : ''}}</td>
                            <td>{{$v['address'] ? $v['address']['position_address'].' '.$v['address']['address'] : ''}}</td>
                            <td>
                            @if(isset($v['member_water_bill']) && count($v['member_water_bill']))
                                <div class="buyer">{{$v['total_waterbill_num']}}
                                    <p member_id="{{$v['id']}}"></p>
                                    <div class="buyer-info">
                                        <em></em>
                                        <div class="con">
                                            <h3><i style="width:180px;"></i><span>水票信息</span></h3>
                                            @foreach($v['member_water_bill'] as $m)
                                                <dl>
                                                    <dt style="width: 250px;">{{$m['goods_name']}}：</dt>
                                                    <dd style="width: 100px;">{{$m['rest_num']}}</dd>
                                                </dl>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                            @else
                                {{$v['total_waterbill_num']}}
                            @endif
                        </td>
                        <td>
                            <div class="buyer"> {{ $v['initial_bucket_num'] + $v['total_bucket_num'] - $v['total_back_bucket_num'] - $v['cash_bucket_num'] - $v['self_bucket_num']}}
                                <p member_id="{{$v['id']}}"></p>
                                <div class="buyer-info">
                                    <em></em>
                                    <div class="con">
                                        <h3><i></i><span>水桶信息</span></h3>
                                        {{--<dl>
                                            <dt>总 水 桶：</dt>
                                            <dd>{{ $v['initial_bucket_num'] + $v['self_bucket_num'] + $v['total_bucket_num'] - $v['total_back_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>自 备 桶：</dt>
                                            <dd>{{$v['self_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>押 金 桶：</dt>
                                            <dd>{{$v['cash_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>借 用 桶：</dt>
                                            <dd>{{$v['borrow_bucket_num']}}</dd>
                                        </dl>--}}
                                        <dl>
                                            <dt>总 送 桶：</dt>
                                            <dd>{{$v['total_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>总 回 桶：</dt>
                                            <dd>{{$v['total_back_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>自 备 桶：</dt>
                                            <dd>{{$v['self_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>押 金 桶：</dt>
                                            <dd>{{$v['cash_bucket_num']}}</dd>
                                        </dl>
                                        <dl>
                                            <dt>初 始 桶：</dt>
                                            <dd>{{$v['initial_bucket_num']}}</dd>
                                        </dl>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <td>
                            {{$v['deposit']}}
                        </td>
                        <td style="color: @if($v['status'] > 0) blue @else red @endif">{{$v['status_text']}}</td>
                        <td>
                            <ul class="list-inline">
                                <li><a href="{{urlPlat('single','getBillRecord',['id'=>$v['id'],'name'=> isset($v['address']['name']) ? $v['address']['name'] : ''])}}">水票明细</a></li>
                                <li><a href="{{urlPlat('single','getBucketRecord',['id'=>$v['id'],'name'=> isset($v['address']['name']) ? $v['address']['name'] : ''])}}">水桶明细</a></li>
                            </ul>
                        </td>
                        @if(isset($shopInfo['send_mode']) && $shopInfo['send_mode'] == 2)
                            <td>{{(isset($v['worker']) && $v['worker']) ? $v['worker']['name'] : ''}}</td>
                        @endif
                        <td>{{$v['created_at']}}</td>
                        @if(plat_identify() == 'account')
                        <td>
                            <a title="代客下单"
                               href="{{urlPlat('single','getAddOrder',['id'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id']])}}">代客下单</a>
                            <div class="select_box">
                                <a href="javascript:;" class="more">更多操作</a>
                                <ul class="optionBox">
                                    @if(!$v['import_bucket'] || !$v['import_waterbill'])
                                        <li>
                                            <a title="老客户导入"
                                               href="{{urlPlat('single','getMemberImport',['id'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id']])}}">老客户导入</a>
                                        </li>
                                    @endif
                                    <li>
                                        <a title="押金管理"
                                           href="{{urlPlat('single','getMemberCash',['keyword'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id'],'type'=>1])}}">押金管理</a>
                                    </li>
                                    <li>
                                        <a title="水票充值"
                                           href="{{urlPlat('single','getMemberCharge',['id'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id']])}}">水票充值</a>
                                    </li>
                                    <li>
                                        <a title="账号移交"
                                           href="{{urlPlat('single','getMemberMove',['id'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id']])}}">账号移交</a>
                                    </li>
                                    <li>
                                        <a title="购买限制"
                                           href="{{urlPlat('single','getMemberBuy',['id'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id']])}}">购买限制</a>
                                    </li>
                                    @if(isset($shopInfo['send_mode']) && $shopInfo['send_mode'] == 2)
                                        <li>
                                            <a title="绑定送水工"
                                               onclick="bindWorker('{{$v['id']}}','{{$v['shop_id']}}','{{$v['worker_id']}}')">绑定送水工</a>
                                        </li>
                                    @endif
                                    @if(!$v['wx_openid'])
                                        <li>
                                            <a title="给新增的用户关联微信信息"  onclick="bindWxQrcode('{{$v['id']}}','{{$v['shop_id']}}','{{$v['admin_id']}}','{{$v['address']['name']}}','{{$v['address']['mobile']}}','{{$v['address']['position_address'].' '.$v['address']['address']}}')"
                                               href="javascript:;">生成微信关联码</a>
                                        </li>
                                    @endif
                                    <li>
                                        <a title="编辑"
                                           href="{{urlPlat('single','getMemberEdit',['id'=>$v['id'],'admin_id'=>$v['admin_id'],'shop_id'=>$v['shop_id'],'address_id'=>$v['address'] ? $v['address']['id'] : 0])}}">编辑</a>
                                    </li>
                                    @if($v['status'] == 1)
                                        <li>
                                            <a href="{{urlPlat('single','anyChangeMemberStatus',['status'=>0,'ids'=>$v['id'],'shop_id'=>$v['shop_id']])}}"
                                               class="ajax-get" style="color:red">禁用</a>
                                        </li>
                                    @else
                                        <li>
                                            <a href="{{urlPlat('single','anyChangeMemberStatus',['status'=>1,'ids'=>$v['id'],'shop_id'=>$v['shop_id']])}}"
                                               class="ajax-get" style="color:blue">启用</a>
                                        </li>
                                    @endif
                                </ul>
                            </div>
                        </td>
                        @endif
                    </tr>
                @endforeach
            @else
                <td colspan="15" class="text-center"> aOh! 暂时还没有内容!</td>
            @endif
            </tbody>
        </table>
    </div>
    <div class="page">
        @if($rows['last_page']>1)
            <div>
                <a class="first" href="{{urlPlat('single','getMember',['page'=>1,'keyword'=>$keyword,'type'=>$type])}}">首页</a>
            @if($rows['prev_page_url'])
                    <a class="prev" href="{{$rows['prev_page_url']}}">&lt;&lt;</a>
                @endif
                @if(count($rows['pageNoList']))
                    @foreach($rows['pageNoList'] as $v)
                        @if($rows['current_page'] == $v)
                            <span class="current">{{$v}}</span>
                        @else
                            <a class="num" href="{{urlPlat('single','getMember',['page'=>$v,'keyword'=>$keyword,'type'=>$type])}}">{{$v}}</a>
                        @endif
                    @endforeach
                @endif
                @if($rows['next_page_url'])
                    <a class="next" href="{{$rows['next_page_url']}}">&gt;&gt;</a>
                @endif
                <a class="last" href="{{urlPlat('single','getMember',['page'=>$rows['last_page'],'keyword'=>$keyword,'type'=>$type])}}">末页</a>
                <span class="rows">共 {{$rows['total']}} 条记录</span>
            </div>
        @endif
    </div>
@endsection

@section('script')
    <script type="text/javascript">


        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var shop_id = $("#sch-sort-txt").attr("data");
            var query = $('.search-form').find('input').serialize();
            var type = $('#type').val();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query + '&type=' + type;
            } else {
                url += '?' + query + '&type=' + type;
            }
            window.location.href = url;
        });

        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down").hover(function () {
            $("#sub-sch-menu").removeClass("hidden");
        }, function () {
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function () {
            $(this).click(function () {
                var text = $(this).text();
                $("#sch-sort-txt").text(text).attr("data", $(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
                window.location.href = '{{urlPlat('single','getMember')}}';
            })
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function(event){
            if(event.keyCode===13){
                $("#search").click();
            }
        });

        $(".more").click(function () {
            var thisul = $(this).parent().find("ul");
            if (thisul.css("display") == "none") {
                if (thisul.height() > 180) {
                    thisul.css({height: "180" + "px", "overflow-y": "scroll"})
                };
                thisul.fadeIn("100");
                thisul.hover(function () {
                }, function () {
                    thisul.fadeOut("100");
                })
                thisul.find("li").click(function () {
                    thisul.fadeOut("100");
                }).hover(function () {
                    $(this).addClass("hover");
                }, function () {
                    $(this).removeClass("hover");
                });
            }
            else {
                thisul.fadeOut("fast");
            }

        });

        function bindWorker(id, shop_id,worker_id) {
            layer.open({
                type: 2,
                title: '绑定送水工',
                area: ['400px', '150px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{{urlPlat('single','getBindWorker')}}?id=' + id + '&shop_id=' + shop_id+ '&worker_id=' + worker_id
            });
        }
        function bindWxQrcode(id, shop_id,admin_id,name,mobile,address) {
            layer.open({
                type: 2,
                title: '生成微信关联码',
                area: ['600px', '500px'],
                fixed: false, //不固定
                maxmin: true,
                content: '{{urlPlat('single','getSyncQrCode')}}?id=' + id + '&shop_id=' + shop_id+ '&admin_id=' + admin_id+ '&name=' + name+ '&mobile=' + mobile+ '&address=' + address
            });
        }

    </script>
@endsection
